/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class LargestNumberGreaterThanTwiceofOthers {
	public int dominantIndex(int[] nums) {
		if (nums.length == 1) {
			return 0;
		}
		int largestIndex = 0;
		int seclargIndex = -1;
		for (int i = 1; i < nums.length; i++) {
			if (nums[i] > nums[largestIndex]) {
				seclargIndex = largestIndex;
				largestIndex = i;
			} else if (seclargIndex == -1 || nums[i] > nums[seclargIndex]) {
				seclargIndex = i;
			}
		}

		if (seclargIndex == -1) {
			if (nums[largestIndex] == 0) {
				return largestIndex;
			} else {
				return -1;
			}
		} else {
			if (nums[largestIndex] >= nums[seclargIndex] * 2) {
				return largestIndex;
			} else {
				return -1;
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] nums = { 0 };
		System.out.println(new LargestNumberGreaterThanTwiceofOthers().dominantIndex(nums));
	}

}
